package com.yycx.module.bus.provider.service;

import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.module.bus.client.entity.BusCustomBalance;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.entity.BusSaleman;
import com.yycx.module.bus.client.entity.BusSalemanBalance;
import com.yycx.common.mybatis.base.service.IBaseService;
import com.yycx.module.bus.client.entity.hy.HyOrder;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 业务员资保金收支记录 接口
 *
 * @author flyme
 * @date 2023-08-24
 */
public interface BusSalemanBalanceService extends IBaseService<BusSalemanBalance> {

    /**
     * 根据订单ID查询
     *
     * @param orderId
     * @return
     */
    List<BusSalemanBalance> selectListByOrderId(Serializable orderId);


    /**
     * 根据订单ID删除
     *
     * @param orderId
     * @return
     */
    boolean removeByOrderId(Serializable orderId);

    /**
     * 删除货款抵扣并更新账户余额
     *
     * @param orderId
     */
    void updateSaleManBalance(Serializable orderId);

    /**
     * 拆分金额
     *
     * @param saleManBalanceId
     * @param amount
     * @param orderId
     * @param orderDetailsId
     * @return
     */
    BusSalemanBalance cfAmount(Long saleManBalanceId, BigDecimal amount, String orderId, String orderDetailsId);

    /**
     * 抵扣资保金账户金额
     *
     * @param saleManBalanceId
     * @param customBond
     * @param orderId
     * @param orderDetailsId
     * @return
     */
    BusSalemanBalance deductionAmount(Long saleManBalanceId, BigDecimal customBond, String orderId, String orderDetailsId);

    /**
     * 撤销和订单明细的关联
     *
     * @param saleManBalanceId
     * @return
     */
    Boolean revokeOrderDetailsUse(Long saleManBalanceId);

    /**
     * 撤销拆分
     *
     * @param saleManBalanceId
     * @return
     */
    ResultBody revokeCfAmount(Long saleManBalanceId);


    /**
     * 计算资保金余额
     *
     * @param saleManId
     * @param companyId
     * @return
     */
    BigDecimal totalAmount(Long saleManId, Long companyId);

    /**
     * 更新拆分金额
     *
     * @param saleManBalanceId
     * @param amount
     * @return
     */
    void updateCfAmount(Long saleManBalanceId, BigDecimal amount);


    /**
     * 更新认款状态
     *
     * @param rkId
     * @param balanceState
     * @return
     */
    boolean updateBalanceState(Long rkId, Integer balanceState);


    /**
     * 保存资保金
     *
     * @param payment
     */
    void saveSalManBalance(BusPayment payment);

    /**
     * 保存资保金初始值
     *
     * @param amount
     * @param saleManId
     */
    void saveSalManBalance(Long saleManId,BigDecimal amount);
}
